<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@include file="/common/mytags.jsp" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>新增编辑菜单信息</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <link rel="stylesheet" type="text/css" href="<%=basePath%>common/frame/layui/css/layui.css" media="all">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>common/css/gobal.css" media="all">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>common/css/animate.css" media="all">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>backstage/css/common.css" media="all">
    <link rel="stylesheet" type="text/css" href="<%=basePath%>backstage/css/createActive.css" media="all">
</head>
<body>


<div class="larry-fluid larry-wrapper">

    <div class="layui-row lay-col-space20">
        <div class="layui-cos-xs12 layui-col-sm12 layui-col-md12 layui-col-lg8">
            <section class="larry-body animated fadeInRightBig">
                <div class="larry-body-content clearfix" >

                    <form class="layui-form" action="" method="post">
                        <c:if test="${ empty requestScope.child}">
                            <div class="layui-form-item">
                                <label class="layui-form-label">菜单属性</label>
                                <div class="layui-input-block"  style="width: 30%;">
                                    <select name="attribute" id="attribute" lay-verify="required"  class="layui-input layui-select">
                                        <option value="" >请选择</option>
                                        <c:forEach items="${requestScope.attributes}" var="a">
                                            <option <c:if test="${requestScope.attribute==a.value}">selected</c:if>  value="${a.value}"  >${a.name}</option>
                                        </c:forEach>
                                    </select>
                                </div>
                            </div>
                        </c:if>

                        <div class="layui-form-item">
                            <label class="layui-form-label">菜单名称</label>
                            <div class="layui-input-block">
                                <input type="text" name="name" id="name" maxlength="10" value="${requestScope.menu.name}" lay-verify="required" autocomplete="off" placeholder="请输入菜单的名称"
                                       class="layui-input">
                            </div>
                        </div>
                        
                        <div class="layui-form-item">
                            <label class="layui-form-label">菜单描述</label>
                            <div class="layui-input-block">
                                <input type="text" name="describe" maxlength="64" value="${requestScope.menu.describe}"  autocomplete="off" placeholder="请输入菜单的详细描述"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">菜单图标</label>
                            <div class="layui-input-block">
                                <input type="text" name="icon"  maxlength="64" id="icon" value="<c:out value="${requestScope.menu.icon}"></c:out>"  aautocomplete="off"  class="layui-input" placeholder="请输入菜单图标">
                            </div>
                        </div>
                         <div class="layui-form-item">
			                <label class="layui-form-label">菜单URL</label>
			                <div class="layui-input-block">
			                   <input type="text" name="url"  maxlength="64" id="url" value="${requestScope.menu.url}"   aautocomplete="off"  class="layui-input" placeholder="请输入菜单地址URL">
                            </div>
			            </div>
			             <div class="layui-form-item">
			                <label class="layui-form-label">权限代码</label>
			                <div class="layui-input-block">
			                   <input type="text" name="code"  maxlength="64" id="code" value="${requestScope.menu.code}"   aautocomplete="off"  class="layui-input" placeholder="请输入菜单的权限代码">
                            </div>
			            </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">代码文件</label>
                            <div class="layui-input-block">
                                <input type="radio" name="open" value="true" title="开启"  >
                                <input type="radio" name="open" value="false" title="关闭" checked >
                            </div>
                        </div>
                        <c:if test="${requestScope.type!=0}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">菜单类型</label>
                            <div class="layui-input-block">
                                <input type="radio" name="type" value="0" title="目录" <c:if test="${requestScope.menu.type==0}">checked</c:if> >
                                <input type="radio" name="type" value="1" title="菜单" <c:if test="${requestScope.menu.type==1 || empty requestScope.menu}">checked</c:if> >
                                <input type="radio" name="type" value="2" title="按钮" <c:if test="${requestScope.menu.type==2}">checked</c:if> >
                            </div>
                        </div>
                        </c:if>
                        <div class="layui-form-item" >
                            <div style="float: left;margin-right: 30px;">
                                <label class="layui-form-label">是否展开</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="spread" value="1" title="展开" <c:if test="${requestScope.menu.spread=='true'}">checked</c:if> >
                                    <input type="radio" name="spread" value="2" title="折叠" <c:if test="${requestScope.menu.spread=='false' || empty requestScope.menu}">checked</c:if> >
                                </div>
                            </div>
                            <div  style="float: left;">
                                <label class="layui-form-label">是否必选</label>
                                <div class="layui-input-block">
                                    <input type="radio" name="checked" value="1" title="必选"  <c:if test="${requestScope.menu.checked==1}">checked</c:if> >
                                    <input type="radio" name="checked" value="2" title="忽略"  <c:if test="${requestScope.menu.checked==2 || empty requestScope.menu}">checked</c:if> >
                                </div>
                            </div>
                        </div>



                       
                        <div class="layui-form-item" style="text-align: center;">
                            <button class="layui-btn" lay-submit="" id="ok" lay-filter="ok">确定</button>
                            <button type="layui-btn" id="cancle" class="layui-btn layui-btn-primary">取消</button>
                        </div>
                        <input type="hidden" id="menuId" name="menuId" value="${requestScope.menu.menuId}">
                        <c:if test="${requestScope.child==1}">
                            <input type="hidden" id="attribute" name="attribute" value="${requestScope.attribute}">
                        </c:if>
                        <c:if test="${empty requestScope.menu.menuId}">
                            <input type="hidden" id="num" name="num" value="${requestScope.maxNum}">
                            <input type="hidden" id="authorityId" name="authorityId" value="${requestScope.authorityId}">
                        </c:if>
                        <c:if test="${requestScope.type==0}">
                            <input type="hidden" id="type" name="type" value="0">
                        </c:if>
                        <c:if test="${not empty requestScope.fatherId}">
                            <input type="hidden" id="fatherId" name="fatherId" value="${requestScope.fatherId}">
                            <input type="hidden" id="parentId" name="parentId" value="${requestScope.parentId}">
                        </c:if>
                        <input type="hidden" id="check_code" value="1" >
                    </form>
                </div>
            </section>
        </div>
    </div>
</div>

<script type="text/javascript" src="<%=basePath%>common/frame/layui/layui.js"></script>
<script>

    layui.config({
        base: "<%=basePath%>common/larrylib/",
        version: '201708031'
    }).use(['jquery', 'form', 'upload'], function () {
        var $ = layui.jquery, form = layui.form;


        form.verify({
            number: [
                /^[0-9]{0,5}$/
                ,'请填写正确的数字！'
            ],
            phone:[
                /^1[34578]\d{9}$/
                ,'请填写正确的手机号！'
            ],
            money:[
                /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
                ,'请填写正确格式的价格！'
            ],
            range:[
                /(^[1-9]{1,10}~[1-9]{1,10}$)/
                ,'请填写正确格式的范围！'
            ]
        });


        $("input[id='code']").blur(function(){
            var code = $("#code").val();
            var menuId = $("#menuId").val();
            if(code != ""){
                $.ajax({
                    url: '<%=basePath%>auth/menu/checkCode',
                    type: 'post',
                    async: false,
                    data: {code:code},
                    dataType: "json",
                    success: function (data) {
                        if(data.state==200){
                            if(menuId==""){
                                $("#check_code").val("2");
                                layer.msg("权限代码已存在，或模糊存在！", {icon: 5});
                            }
                            if(menuId!="" && menuId != data.data.menuId){
                                $("#check_code").val("2");
                                layer.msg("权限代码已存在，或模糊存在！", {icon: 5});
                            }
                            if(menuId!="" && menuId == data.data.menuId){
                                $("#check_code").val("1");
                            }
                        }else{
                            $("#check_code").val("1");
                        }
                    }, error: function () {
                        layer.msg("系统数据处理异常！", {icon: 2});
                    }
                });
            }
        });


        //监听提交
        form.on("submit(ok)", function (data) {
           var type = $("input[name='type']:checked").val();
            var url = $("#url").val();
            var code = $("#code").val();
            if(type==1 || type==2){
                if(url.trim().length==0){
                    top.layer.msg("菜单URL不能为空", {icon: 5});
                    $("#url").focus();
                    return false;
                }
                if(code.trim().length==0){
                    top.layer.msg("权限代码不能为空", {icon: 5});
                    $("#code").focus();
                    return false;
                }

            }
            if(code.trim().length>0){
                var check_code = $("#check_code").val();
                if(check_code=="2"){
                    layer.msg("权限代码已存在，或模糊存在！", {icon: 5});
                    $("#code").focus();
                    return false;
                }
            }

            var loginLoading = top.layer.msg('提交中，请稍候...', {icon: 16, time: false, shade: 0.8});
            $.ajax({
                url: '<%=basePath%>auth/menu/edit',
                type: 'post',
                async: false,
                data: data.field,
                dataType: "json",
                success: function (data) {
                    if (data.state == 200) {
                       // window.setInterval(function(){},1500);
                       top.layer.msg(data.message, {icon: 6});
                       	var index = parent.layer.getFrameIndex(window.name); //当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                        var father = parent.layui.jquery;
                        father("#getSelect").click();
                        return true;
                    } else {
                        top.layer.msg(data.message, {icon: 5});
                        return false;
                    }
                    top.layer.close(loginLoading);
                }, error: function () {
                    top.layer.msg("系统数据处理异常！", {icon: 2});
                    top.layer.close(loginLoading);
                    return false;
                }
            });
        });

        //取消
        $("#cancle").click(function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

    });

</script>
</body>
</html>